import { ref, watch } from "vue";

export default function useModelValue(
  initValue: boolean,
  emitFn: (value: boolean) => any
) {
  const checked = ref(initValue);

  watch(
    () => initValue,
    (newVal: boolean) => {
      checked.value = newVal;
    }
  );

  const handleChecked = () => {
    checked.value = !checked.value;
    emitFn(checked.value);
  };

  return {
    checked,
    handleChecked,
  };
}
